﻿using AiMoWindows.Localization;
using AiMoWindows.Server;
using System.Windows;
using System.Windows.Media;

namespace AiMoWindows.Windows.Download
{
    /// <summary>
    /// InputShareKeyWindow.xaml 的交互逻辑
    /// </summary>
    partial class InputShareKeyWindow : Window
    {
        public string ShareKey => shareKey;
        string shareKey = "";
        public InputShareKeyWindow()
        {
            InitializeComponent();
            SetLanguage();
            string shareKey = Clipboard.GetText(TextDataFormat.Text).Trim();
            if (ServerHelper.IsValidShareKey(shareKey))
            {
                ShareCodeTextbox.Text = shareKey;
            }
        }
        bool IsEnglish => !Local.RunningInChinese;
        void SetLanguage()
        {
            FontFamily = new FontFamily(IsEnglish ? "Bahnschrift Condensed" : "Microsoft Yahei");
            ShareCodeTextBlock.Text = IsEnglish ? "Share Code: " : "分享码：";
            DownloadButton.Content = IsEnglish ? "Download " : "下载";
            CancelButton.Content = IsEnglish ? "Cancel " : "取消";
        }
        void CancelButtonClick(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }
        void DownloadButtonClick(object sender, RoutedEventArgs e)
        {
            if (ServerHelper.IsValidShareKey(ShareCodeTextbox.Text.Trim()))
            {
                shareKey = ShareCodeTextbox.Text.Trim();
                DialogResult = true;
                Close();
            }
            else
            {
                DialogResult = false;
                MessageBox.Show(this, Local.Get("Please input valid ShareKey"));
            }
        }

    }
}
